package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.shopping.domain.Bbs;
import com.ruoyi.shopping.service.IBbsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论坛留言Controller
 *
 * @author scx
 * @date 2022-06-16
 */
@RestController
@RequestMapping("/shopping/bbs")
public class BbsController extends BaseController
{
    @Autowired
    private IBbsService bbsService;

    /**
     * 查询论坛留言列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bbs bbs)
    {
        startPage();
        bbs.setBelongs(DicConstants.BUSINESS_Business.getCode());
        List<Bbs> list = bbsService.selectBbsList(bbs);
        return getDataTable(list);
    }

    /**
     * 导出论坛留言列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:export')")
    @Log(title = "论坛留言", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Bbs bbs)
    {
        List<Bbs> list = bbsService.selectBbsList(bbs);
        ExcelUtil<Bbs> util = new ExcelUtil<Bbs>(Bbs.class);
        return util.exportExcel(list, "论坛留言数据");
    }

    /**
     * 获取论坛留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bbsService.selectBbsById(id));
    }

    /**
     * 新增论坛留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:add')")
    @Log(title = "论坛留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bbs bbs)
    {
        return toAjax(bbsService.insertBbs(bbs));
    }

    /**
     * 修改论坛留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:edit')")
    @Log(title = "论坛留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bbs bbs)
    {
        bbs.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(bbsService.updateBbs(bbs));
    }

    /**
     * 删除论坛留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbs:remove')")
    @Log(title = "论坛留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bbsService.logicDeleteBbs(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
